package Donnees;

import Presentation.FenetrePrincipale;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;
import java.util.ResourceBundle;

public class DbUtil {
 
    public static void close(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                ResourceBundle configBundle = ResourceBundle.getBundle("ressources/Main/Main", Locale.FRENCH);
                FenetrePrincipale.afficherPopupErreur(configBundle.getString("main.errCloseConnexion"));
                e.printStackTrace();
            }
        }
    }
 
    public static void close(Statement statement) {
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                ResourceBundle configBundle = ResourceBundle.getBundle("ressources/Main/Main", Locale.FRENCH);
                FenetrePrincipale.afficherPopupErreur(configBundle.getString("main.errCloseStatement"));
                e.printStackTrace();
            }
        }
    }
    
    public static void close(PreparedStatement preparedStatement) {
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                ResourceBundle configBundle = ResourceBundle.getBundle("ressources/Main/Main", Locale.FRENCH);
                FenetrePrincipale.afficherPopupErreur(configBundle.getString("main.errClosePrepStatement"));
                e.printStackTrace();
            }
        }
    }
 
    public static void close(ResultSet resultSet) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                ResourceBundle configBundle = ResourceBundle.getBundle("ressources/Main/Main", Locale.FRENCH);
                FenetrePrincipale.afficherPopupErreur(configBundle.getString("main.errCloseResultSet"));
                e.printStackTrace();
            }
        }
    }
}
